package cn.col.gszf.mapper;

import cn.col.gszf.model.UserVoteGroupDay;
import cn.col.gszf.pojo.UserVotes;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserVotesMapper extends BaseMapper<UserVotes> {

    @Select("select count(1) from User_votes")
    Integer getSumVotingNums();

    @Select("select count(1) as num from user_votes where create_at " +
            "between #{start} and #{end} group by channel_id order by num desc limit 1")
    Integer getMaxVotingNums(@Param("start") LocalDateTime start,@Param("end") LocalDateTime end);


    @Select("select count(1) as num from user_votes where create_at between #{start} and #{end}" +
            "group by channel_id limit 1")
    Integer countByCreateAtBetween(@Param("start") LocalDateTime start,@Param("end") LocalDateTime end);

    @Select("select create_at,count(channel_id),channel_id from user_votes group by create_at")
    List<UserVoteGroupDay> findNumsGroupByDay();

    @Select("select create_at,count(channel_id),channel_id from user_votes" +
            " where channel_id = #{id} group by create_at")
    List<UserVoteGroupDay> findNumsGroupByDayAndChannelId(@Param("id") Integer channelId);
}
